﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Pout_Porri.Objects.Interface;
using Pout_Porri.Utils;


namespace Pout_Porri.Objects
{
    class Rope : Enemy
    {
        private Animation ropeStand;
        private float valor;
        private double elapsedTime;
        private bool clockwise = true;

        public Rope(Texture2D image, Vector2 position, Vector2 velocity,
                    float Zorder) : base(image, position, velocity)
        {
            this.Mass = 0;
            this.setGrounded(false);
            this.texture = image;
            this.zOrder = Zorder;
            
        }

        public override void configAnimations()
        {
            //Animation marioStand = new Animation("stand", new Vector2(84, 84), 100, 0, 0, 1, Axis.X);
            ropeStand = new Animation("ropeStand", new Vector2(531,123), 100, 0, 0, 1, Axis.X);
            this.addAnimation(ropeStand);
            
            this.spriteTexture = new Texture2D(Game1.graphics.GraphicsDevice, 336, 84);
       
            this.setCurrentAnimation("ropeStand");
            currentState = EnemyStates.stand;
        }

        public void setRotation(float valor)
        {
            this.rotation = valor;
        }

        public void setRotation(GameTime gameTime)
        {

            if (gameTime.TotalGameTime.TotalMilliseconds > elapsedTime + 20)
            {
                 elapsedTime = gameTime.TotalGameTime.TotalMilliseconds;

                 if (clockwise)
                     valor--;
                 else
                     valor++;
                
                this.rotation = Utils.Util.convertDeg2Rad(valor);
                if (this.rotation > Utils.Util.convertDeg2Rad(120))
                {
                    this.rotation = Utils.Util.convertDeg2Rad(120);
                    clockwise = true;
                }
                else if (this.rotation < Utils.Util.convertDeg2Rad(60))
                {
                    this.rotation = Utils.Util.convertDeg2Rad(60);
                    clockwise = false;
                }

            }
        }

        public override void update(GameTime gameTime)
        {
            currentAnimationRect = this.AnimationRect(this.getCurrentAnimation());

            setRotation(gameTime);

            if (currentState == EnemyStates.stand)
            {
                this.setCurrentAnimation("ropeStand");
                this.currentAnimationRect = this.AnimationRect(ropeStand);
            }

            base.update(gameTime);
        }
    }
}
